package com.kaiwukj.android.ufamily.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.kaiwukj.android.mcas.integration.IRepositoryManager;
import com.kaiwukj.android.mcas.mvp.BaseModel;
import com.kaiwukj.android.ufamily.mvp.contract.RecycleVideoContract;
import com.kaiwukj.android.ufamily.mvp.http.api.service.DynamicService;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.CommentParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommentResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * @author Charles
 * @date 2019/8/14.
 * description：Kaiwu
 */
public class RecycleVideoModel extends BaseModel implements RecycleVideoContract.Model {

    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public RecycleVideoModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }


    @Override
    public Observable<Integer> postLike(int id) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .praise(id)
                .compose(RxUtils.handleCode());
    }

    @Override
    public Observable<Integer> postLikeCancel(int id) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .cancelPraise(id)
                .compose(RxUtils.handleCode());
    }

    @Override
    public Observable<ListResp<CommentResult>> requestCommentList(int id, int startId) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .fetchComment(id, startId, 10)
                .compose(RxUtils.handleResult());
    }

    @Override
    public Observable<Integer> requestCommentOther(CommentParams request) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .comment(getRequestBody(mGson.toJson(request)))
                .compose(RxUtils.handleCode());
    }
}
